package com.pc.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pc.entity.Orderlist;
import com.pc.mapper.OrderlistMapper;
import com.pc.utils.Topfood;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class OrderListService {
    @Resource
    private OrderlistMapper orderlistMapper;

    //新增订单
    public boolean addOrder(Orderlist order){
        int insert = orderlistMapper.insert(order);
        return insert!=0;
    }


    //查询卖的最好的食品
    public List<Topfood>  getTopList(){
        List<Object> topFood = orderlistMapper.getTopFood1();
        List<Object> topFood2 = orderlistMapper.getTopFood2();
        ArrayList<Topfood> topfoods = new ArrayList<>();

        for(int i=0;i<10;i++){
            Topfood topfood = new Topfood();
            topfood.setFoodname((String) topFood2.get(i));

            topfood.setCountfood(topFood.get(i)+"");
            topfoods.add(topfood);
        }

        return topfoods;

    }
    //查询卖的最差的10个
    public List<Topfood> getEndList(){
        List<Object> endFood1 = orderlistMapper.getEndFood1();
        List<Object> endFood2 = orderlistMapper.getEndFood2();
        ArrayList<Topfood> topfoods = new ArrayList<>();

        for(int i=0;i<10;i++){
            Topfood topfood = new Topfood();
            topfood.setFoodname((String) endFood1.get(i));

            topfood.setCountfood(endFood2.get(i)+"");
            topfoods.add(topfood);
        }

        return topfoods;
    }

    //获得所有订单
    public List<Orderlist> getAllOrder(){
        QueryWrapper<Orderlist> wrapper = new QueryWrapper<>();
        return orderlistMapper.selectList(wrapper);
    }
}
